//
//  RGSearchUserListCell.m
//  RedGrass
//
//  Created by wukong on 2019/2/16.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGSearchUserListCell.h"
#import <UIImageView+WebCache.h>

@interface RGSearchUserListCell()

@property (strong, nonatomic) UIImageView *userImg;
@property (strong, nonatomic) UILabel *userNick;
@property (strong, nonatomic) UILabel *fansCount;
@property (strong, nonatomic) UIButton *focusBtn;

@end

@implementation RGSearchUserListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor blackColor];
        [self initSubView];
    }
    return self;
}

-(void)initSubView{
    [self.contentView addSubview:self.userImg];
    [_userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(58, 58));
        make.left.mas_equalTo(self.contentView).mas_offset(15);
        make.centerY.mas_equalTo(self.contentView).mas_offset(0);
    }];
    [self.contentView addSubview:self.userNick];
    [_userNick mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.userImg.mas_trailing).offset(10);
        make.top.mas_equalTo(self.userImg.mas_top).mas_offset(-1);
    }];
    [self.contentView addSubview:self.fansCount];
    [_fansCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.userImg.mas_trailing).offset(10);
        make.bottom.equalTo(self.userImg.mas_bottom).offset(-1);
    }];
    [self.contentView addSubview:self.focusBtn];
    [_focusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-15);
        make.size.mas_equalTo(CGSizeMake(70, 30));
        make.centerY.mas_equalTo(0);
    }];
}

#pragma mark - public
-(void) setModel:(RGVideoUserInfoModel *)model{
    if(model == nil){
        return;
    }
    _model = model;
    [_userImg sd_setImageWithURL:[NSURL URLWithString:SafeStr(model.image)] placeholderImage:IMAGE_NAMED(@"头像1")];
    _userNick.text = SafeStr(model.nickname);
    _fansCount.text = [NSString stringWithFormat:@"粉丝数量:%ld",model.fansCounts];
    if(model.meFollowmTa){//已关注
        _focusBtn.selected = YES;
        _focusBtn.backgroundColor = UICOLOR_WITH_RGBINT(0x716d7f);
    }else{
        _focusBtn.selected = NO;
        _focusBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
       
    }
}

#pragma mark - response

-(void)addOrCancel:(UIButton *)button{
    if(self.focusStatusChangeBlock){
        self.focusStatusChangeBlock();
    }
}

#pragma mark - getter

-(UIImageView *)userImg{
    if(!_userImg){
        _userImg = [[UIImageView alloc]init];
        _userImg.image = IMAGE_NAMED(@"头像1");
        ViewRadius(_userImg, 29);
    }
    return _userImg;
}

-(UILabel *)userNick{
    if(!_userNick){
        _userNick = [[UILabel alloc]init];
        _userNick.font = FONT(customFontName, 15);
        _userNick.textColor = UICOLOR_WITH_RGBINT(0x666666);
        _userNick.text = @"test";
    }
    return _userNick;
}

-(UILabel *)fansCount{
    if(!_fansCount){
        _fansCount = [[UILabel alloc]init];
        _fansCount.font = FONT(customFontName, 13);
        _fansCount.textColor = UICOLOR_WITH_RGBINT(0x999999);
        _fansCount.text = @"ree";
    }
    return _fansCount;
}

-(UIButton *) focusBtn{
    if(!_focusBtn){
        _focusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_focusBtn setTitle:@"关注" forState:UIControlStateNormal];
        [_focusBtn setTitle:@"已关注" forState:UIControlStateSelected];
        _focusBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
        _focusBtn.titleLabel.font = FONT(customFontName, 13);
        [_focusBtn addTarget:self action:@selector(addOrCancel:) forControlEvents:UIControlEventTouchUpInside];
        _focusBtn.layer.cornerRadius = 4;
        _focusBtn.layer.masksToBounds = YES;
    }
    return _focusBtn;
}

@end
